<?php

namespace Install\Controller;

use Think\Storage;

/**
 * 升级安装
 * @author ZXZ <zxz054321@163.com>
 */
class UpdateController extends InstallController {

    private $dateVersion = '20150612';
    private $lockFile = './update.lock';

    protected function _initialize() {
        if (Storage::has($this->lockFile)) {
            if ($this->dateVersion == Storage::read($this->lockFile))
                $this->error('不可重复执行升级程序！');
        }
    }

    public function index() {
        $this->excute();

        // 写入升级锁定文件，避免多次重复升级
        Storage::put($this->lockFile, $this->dateVersion);

        echo 'done!';
    }

    /**
     * 升级所执行的操作
     */
    private function excute() {
        //write some code here
    }

}
